#include <dbg.h>
#include <gtest/gtest.h>
using namespace std;

class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        vector<string> res;
        if (nums.empty()) {
            return res;
        }

        int start = nums[0];
        int end = nums[0];
        for (int i = 1; i < nums.size(); ++i) {
            if (nums[i] == end + 1) {
                end = nums[i];
            } else {
                res.push_back(format(start, end));
                start = end = nums[i];
            }
        }
        res.push_back(format(start, end));

        return res;
    }

private:
    string format(int a, int b) {
        return a == b ? to_string(a) : to_string(a) + "->" + to_string(b);
    }
};

TEST(TEST1, summaryRanges) {
    Solution s;

    vector<int> nums = {0, 1, 2, 4, 5, 7};
    vector<string> ans = {"0->2", "4->5", "7"};
    EXPECT_EQ(s.summaryRanges(nums), ans);
}

TEST(TEST2, summaryRanges) {
    Solution s;

    vector<int> nums = {0, 2, 3, 4, 6, 8, 9};
    vector<string> ans = {"0", "2->4", "6", "8->9"};
    EXPECT_EQ(s.summaryRanges(nums), ans);
}

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}